package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo13Sort {
  def main(args: Array[String]): Unit = {
    // 构建Spark上下文环境
    val conf: SparkConf = new SparkConf()
    conf.setAppName("Demo12MapValues")
    conf.setMaster("local")
    val sc: SparkContext = new SparkContext(conf)

    // 1、读取students、scores数据
    val stuRDD: RDD[String] = sc.textFile("Spark/data/stu/students.txt")

    // 2、按年龄排序 倒序
    /**
     * sortBy 指定按什么进行排序 默认升序
     * ascending = false 表示降序
     */
    stuRDD.sortBy(line => line.split(",")(2), ascending = false).foreach(println)

  }

}
